package com.cn.zengzeng.spbzengzeng.accept;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cn.zengzeng.spbzengzeng.utils.MailUtils;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**
 * @Description:
 * @Author: zhangzengzeng
 * @Date: 2021/7/8 9:35
 */
@Component
@Slf4j
public class ConsumerAccept {
    @RabbitListener(queues = "loginEmail") //侦听队列
    public void loginAccept (String param) {
        JSONObject jsonObject = JSON.parseObject(param);
        String email = jsonObject.getString("email");
        String account = jsonObject.getString("account");
        log.info("发送激活邮件到{}邮箱",email);
        boolean b = MailUtils.sendMail(email,MailUtils.getMailHtml(account),"warehouse-验证邮件");
        if(b){
            log.info("发送成功!");
        }
    }
    @RabbitListener(queues = "forgetPassEmail_topic") //侦听队列
    public void forgetPassAccept (String param) {
        JSONObject jsonObject = JSON.parseObject(param);
        String email = jsonObject.getString("email");
        String verificationCode = jsonObject.getString("verificationCode");
        log.info("发送验证邮件到{}邮箱,验证码:{}",email,verificationCode);
        boolean b = MailUtils.sendMail(email,MailUtils.getForgetPassMailHtml(verificationCode),"warehouse-验证邮件");
        if(b){
            log.info("发送成功!");
        }
    }
    @RabbitListener(queues = "topic.messages") //侦听队列
    public void aVoid (Message message, Channel channel,String data) throws IOException {
        long deliveryTag=message.getMessageProperties().getDeliveryTag();

        log.info("收到的信息是{}",data);
     /*   //deliveryTag签收的消息标签
        //multiple 是否批量签收
        channel.basicAck(deliveryTag,false);//签收

        //deliveryTag签收的消息标签
        //multiple 是否批量签收
        //是否从新入队  （将这条拒收的消息又重新存放带队列中）
        channel.basicNack(deliveryTag,false,false);//拒收-支持批量
        //deliveryTag签收的消息标签
        //multiple 是否批量签收
        channel.basicReject(deliveryTag,true);//拒收-不支持批量*/
    }
}
